package com.carl.zeus.model.system;

import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.FieldStrategy;
import com.carl.zeus.common.emnu.UserStatus;
import com.carl.zeus.util.IdEntity;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.io.Serializable;
import java.util.Date;


/**
 * <p>
 * 
 * </p>
 *
 * @author carl
 * @since 2017-02-13
 */
@Data
@ToString
@AllArgsConstructor
@NoArgsConstructor
@TableName("sys_user")
public class SysUser extends Model<SysUser> {

    private static final long serialVersionUID = 1L;

    private Long id;

    private String username;

    /**
     * 用户昵称
     */
	private String nickname;

	/**
	 * 头像
	 */
	private String avatar;

    /**
     * 邮箱|登录帐号
     */
	private String email;
    /**
     * 密码
     */
	@JsonIgnore
	private String password;
	@JsonIgnore
	private String salt;
    /**
     * 最后登录时间
     */
	@JSONField(format="yyyy-MM-dd HH:mm:ss")
	@TableField("last_login_time")
	private Date lastLoginTime;
    /**
     * 1:有效，0:禁止登录
     */
	private Integer status;

	@TableField(exist = false)
	private UserStatus state;

	@TableField(exist = false)
	private Date leaveTime;

	/**
     * 最后修改时间
     */
	@JSONField(format="yyyy-MM-dd HH:mm:ss")
	@TableField(value="last_update_time",validate=FieldStrategy.IGNORED)
	private Date lastUpdateTime;
	/**
     * 创建时间
     */
	@JSONField(format="yyyy-MM-dd HH:mm:ss")
	@TableField(value="create_time")
	private Date createTime;

	/**
	 * 用户所对应的角色id
	 */
	@TableField(exist = false)
	private String roleIds;
	/**
	 * 用户所对应的角色名称
	 */
	@TableField(exist = false)
	private String roleNames;

	public SysUser(SysUser user) {
		super();
		this.id = user.getId();
		this.username = user.getUsername();
		this.nickname = user.getNickname();
		this.email = user.getEmail();
		this.password = user.getPassword();
		this.createTime = user.getCreateTime();
		this.lastLoginTime = user.getLastLoginTime();
		this.status = user.getStatus();
		this.lastUpdateTime = user.getLastUpdateTime();
	}

	@Override
	protected Serializable pkVal() {
		return this.id;
	}
}
